package com.acme.bankapp.service;

import com.acme.bankapp.domain.Bank;
import com.acme.bankapp.domain.Client;

/**
 * 
 * Performs operations with Clients in a Bank:
 * adds a Client to the Bank,
 * displays information about Clients and Accounts (in various forms).
 *
 */
public class ClientService {
	Bank bank;

	/**
	 * Constructs Service with specified Bank.
	 * @param bank
	 */
	public ClientService(Bank bank) {
		this.bank = bank;
	}

	/**
	 * Delegate method for Bank.addClient().  
	 * Adds a client object to the bank with specified initial balance.  
	 * @param client Client object to be added to Bank.clients.
	 * @param initialBalance Initial balance.
	 */
	public void addClient(Client client, double... initialBalance) {
		bank.addClient(client, initialBalance);
	}

	/**
	 * Displays specified Client object's info in single-line form.
	 * @param client - desired Client object.
	 */
	public void showClient(Client client) {
		System.out.println(client);
	}

	/**
	 * Displays specified Client object's info in multiline form if needed.
	 * @param client - desired Client object.
	 * @param verbose - if true, then multiline.
	 */
	public void showClient(Client client, boolean verbose) {
		if (verbose) {
			System.out.println("\n--- Client info:");
			showClient(client);
			System.out.println();
		}
	}

	/**
	 * Finds Client by name and displays its info in single-line form.
	 * @param clientName - Name of the client.
	 */
	public void showClient(String clientName) {
		showClient(bank.getClientByName(clientName));
	}

	/**
	 * Finds Client by name and displays its info in multi-line form if needed.
	 * @param clientName - Name of the client.
	 * @param verbose - If true, then multiline.
	 */
	public void showClient(String clientName, boolean verbose) {
		showClient(bank.getClientByName(clientName), verbose);
	}

	/**
	 * Displays a list of clients' names.
	 */
	public void showAllClientNames() {
		System.out.println("\n--- List of all client names:");
		for (Client client : bank.getClients()) {
			System.out.println(client.getName() + ", " + client.getGender());
		}
		System.out.println();
	}

	/**
	 * Displays a list of client infos.
	 */
	public void showAllAccounts() {
		System.out.println("\n--- List of all accounts for all clients:");
		for (Client client : bank.getClients()) {
			System.out.println(client);
		}
		System.out.println();
	}
}
